/**
 * Copyright (c) 2020 kedacom
 * OpenATC is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 * http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 **/
package com.openatc.model.model;

import lombok.Data;

import java.util.*;

@Data
public class TypeAndPhase {
    private static final Map<String, List<Integer>> typePhaseId = new HashMap<>();
    private String type;
    private List<SimTemPhase> phaseList;

    public TypeAndPhase(String type) {
        this.type = type;
    }

    static {
        List<Integer> type10000106Ids = new ArrayList<>(); // 东向丁字路口相位id
        type10000106Ids.add(1);
        type10000106Ids.add(2);
        type10000106Ids.add(3);
        type10000106Ids.add(5);
        type10000106Ids.add(7);
        type10000106Ids.add(8);
        typePhaseId.put("100-001-06",type10000106Ids);

        List<Integer> type10000206Ids = new ArrayList<>(); // 南向丁字路口相位id
        type10000206Ids.add(1);
        type10000206Ids.add(2);
        type10000206Ids.add(3);
        type10000206Ids.add(5);
        type10000206Ids.add(6);
        type10000206Ids.add(7);
        typePhaseId.put("100-002-06",type10000206Ids);

        List<Integer> type10000306Ids = new ArrayList<>(); // 西向丁字路口相位id
        type10000306Ids.add(1);
        type10000306Ids.add(3);
        type10000306Ids.add(4);
        type10000306Ids.add(5);
        type10000306Ids.add(6);
        type10000306Ids.add(7);
        typePhaseId.put("100-003-06",type10000306Ids);

        List<Integer> type10000406Ids = new ArrayList<>(); // 北向丁字路口相位id
        type10000406Ids.add(1);
        type10000406Ids.add(3);
        type10000406Ids.add(4);
        type10000406Ids.add(5);
        type10000406Ids.add(7);
        type10000406Ids.add(8);
        typePhaseId.put("100-004-06",type10000406Ids);
    }

    public List<Channel> getTypeChannels() {
        List<Channel> channels = new ArrayList<>();
        if ("101-000-08".equals(type)) {
            channels.add(Channel.getChannelById(1));
            channels.add(Channel.getChannelById(2));
            channels.add(Channel.getChannelById(4));
            channels.add(Channel.getChannelById(5));
            channels.add(Channel.getChannelById(6));
            channels.add(Channel.getChannelById(8));
            channels.add(Channel.getChannelById(9));
            channels.add(Channel.getChannelById(10));
            channels.add(Channel.getChannelById(12));
            channels.add(Channel.getChannelById(13));
            channels.add(Channel.getChannelById(14));
            channels.add(Channel.getChannelById(16));
        } else if ("100-001-06".equals(type)) {
            channels.add(Channel.getChannelById(1));
            channels.add(Channel.getChannelById(6));
            channels.add(Channel.getChannelById(13));
            channels.add(Channel.getChannelById(14));
            channels.add(Channel.getChannelById(8));
            channels.add(Channel.getChannelById(12));
            channels.add(Channel.getChannelById(16));
        } else if ("100-002-06".equals(type)) {
            channels.add(Channel.getChannelById(1));
            channels.add(Channel.getChannelById(2));
            channels.add(Channel.getChannelById(5));
            channels.add(Channel.getChannelById(10));
            channels.add(Channel.getChannelById(4));
            channels.add(Channel.getChannelById(12));
            channels.add(Channel.getChannelById(16));
        } else if ("100-003-06".equals(type)) {
            channels.add(Channel.getChannelById(5));
            channels.add(Channel.getChannelById(6));
            channels.add(Channel.getChannelById(9));
            channels.add(Channel.getChannelById(14));
            channels.add(Channel.getChannelById(4));
            channels.add(Channel.getChannelById(8));
            channels.add(Channel.getChannelById(16));
        } else if ("100-004-06".equals(type)) {
            channels.add(Channel.getChannelById(2));
            channels.add(Channel.getChannelById(9));
            channels.add(Channel.getChannelById(10));
            channels.add(Channel.getChannelById(13));
            channels.add(Channel.getChannelById(4));
            channels.add(Channel.getChannelById(8));
            channels.add(Channel.getChannelById(12));
        }
        return channels;
    }
    /**
     * 根据路口类型获取相位id表
     * @return 需要特殊处理的相位id列表，返回处理后的，无须处理的，返回顺序列表
     */
    public List<Integer> getTypePhaseIds(int phaseCount) {
        List<Integer> typePhaseIds = typePhaseId.get(type);
        if (typePhaseIds == null) {
            typePhaseIds = new ArrayList<>();
            for (int i = 0; i < phaseCount; i++) {
                typePhaseIds.add(i + 1);
            }
        }
        return typePhaseIds;
    }
}
